import requests
def getHTML(url):
    try:
        r=requests.get (url, timeout=1)
        r.raise_for_status()#状态码不是200，会引发HTTPError异常
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return "产生异常"

url='http://www.baidu.com'
print(getHTML(url))
